
org &4000
xor a:call &bc0e


; --- Text ---

ld hl,atext
more:
ld a,(hl)
inc l
or a
jr z,textout
ld b,1
cp 11
jr nz,normaltext
ld b,a
dec a
normaltext:
call 47962
dec b
jr nz,normaltext
jr more

atext:
db 10
db " A Bouncing Pixel!",11,13
db "Optimus/Dirty Minds",11,13
db "     256b shit",0
textout:

; ---- Generating Videoram Y addresses ----

ld hl,49152
ld ix,&4200:ld iy,&4300

ld b,25
char25:

ld de,2048
ld c,d	;c=8
line8:
ld a,h:ld (ix),a:inc ix
ld a,l:ld (iy),a:inc iy
add hl,de

x:
dec c
y:
jr nz,line8
ld de,65536-16384+80
add hl,de
dec b
jr nz,char25


; ---- Main ----

main:
;&3c = inc a
;&3d = dec a

; --- Direction ---

ld hl,ymov
ld a,(y)
or a
jr nz,noy0
ld (hl),&3c
jr noy198
noy0:
cp 198
jr nz,noy198
ld (hl),&3d
noy198:

ld hl,xmov
ld a,(x)
or a
jr nz,nox0
ld (hl),&3c
jr nox159
nox0:
cp 159
jr nz,nox159
ld (hl),&3d
nox159:

; --- Calculate address ---

ld h,&42
ld a,(y)
ymov:
inc a:ld (y),a
ld l,a

ld d,(hl):inc h:ld e,(hl):ex de,hl

ld a,(x)
xmov:
inc a:ld (x),a
ld b,0:srl a:ld c,a
add hl,bc

ld a,(x)
and 1
;ld a,%10000000
ld a,%00100000
jr z,noright
srl a
noright:
ld b,a

; ---- Double Pixel ----

ld c,(hl)
ld (hl),b
ld a,(y)
and 7
cp 7
jr nz,syn2048
ld de,65536-14336+80
jr no2048
syn2048:
ld de,2048
no2048:
push hl:add hl,de:push hl
ld d,(hl):ld (hl),b

; --- Vsync ---

ld b,&f5
vsync0:
in a,(c)
rra
jr nc,vsync0
halt

pop hl:ld (hl),d:pop hl:ld (hl),c

ld bc,&7f00
out (c),c
ld a,&54
out (c),a
inc c
out (c),c
inc a
out (c),a

jp main